#include "VertexCreateAction.h"

using namespace cmn;
using namespace editor_core;

VertexCreateAction::VertexCreateAction( const Vec2& position, IProvider<PolygonEntity*>* parentPolygonProvider ) :
	m_position( position ),
	m_parentPolygonProvider( parentPolygonProvider ),
	m_vertexEntity( 0 )
{}

VertexCreateAction::~VertexCreateAction() {}

bool VertexCreateAction::Commit() {
	PolygonEntity* parentPolygon = m_parentPolygonProvider->GetEntity();

	m_vertexEntity = new VertexEntity( parentPolygon, m_position );
	parentPolygon->AddVertex( m_vertexEntity );
	return true;
}

void VertexCreateAction::Rollback() {
	PolygonEntity* parentPolygon = m_parentPolygonProvider->GetEntity();

	parentPolygon->RemoveVertex( m_vertexEntity );
	delete m_vertexEntity;
	m_vertexEntity = 0;
}

void VertexCreateAction::Recommit() {
	Commit();
}

